﻿package com.ui.data
{
	import com.ui.core.Align;

	import flash.text.TextFormatAlign;

	import com.ui.core.UIComponentData;
	import com.ui.manager.UIManager;

	import flash.text.StyleSheet;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;

	/**
	 * Game Label Data
	 * 
	 * @author Cafe
	 * @version 20100719
	 */
	public class LabelData extends UIComponentData
	{
		public var iconData:IconData;
		public var iconY:int = 0;
		public var textColor:uint;
		public var textFieldFilters:Array;
		public var textFieldAlpha:Number;
		public var textFormat:TextFormat;
		public var styleSheet:StyleSheet;
		public var hGap:int;
		public var text:String;
		public var htmlText:String;
		public var disabledColor:uint = 0x898989;
		public var maxLength:int;
		public var mouseEnabled:Boolean;
		public var padding:int = 0;
		public var autoSize:String;
		public var textX:int;
		public var textY:int;
		public var textAlign:int;
		/**
		 * 处理\r\n变成两次回车的问题
		 */
		public var enterHandler:Boolean;

		override protected function parse( source:* ):void
		{
			super.parse( source );
			var data:LabelData = source as LabelData;
			if (data == null) return;
			if (iconData)
				data.iconData = iconData.clone();
			data.iconY = iconY;
			data.textColor = textColor;
			data.textFieldFilters = (textFieldFilters ? textFieldFilters.concat() : null);
			data.textFormat = textFormat;
			data.styleSheet = styleSheet;
			data.hGap = hGap;
			data.text = text;
			data.htmlText = htmlText;
			data.mouseEnabled = mouseEnabled;
			data.enterHandler = enterHandler;
			data.autoSize = autoSize;
			data.textX = textX;
			data.textY = textY;
			data.width = width;
			data.align = align;
		}

		public function LabelData()
		{
			textColor = 0xEFEFEF;
			textFieldFilters = UIManager.getEdgeFilters( 0x000000, 0.7 );
			textFieldAlpha = 1;
			textFormat = new TextFormat();
			textFormat.align = TextFormatAlign.CENTER;
			textFormat.font = UIManager.defaultFont;
			textFormat.size = 13;
			styleSheet = UIManager.defaultCSS;
			// textFormat.leading = 3;
			textFormat.kerning = true;
			hGap = 1;
			text = "";
			htmlText = "";
			maxLength = 0;
			autoSize = TextFieldAutoSize.LEFT;
		}

		override public function set align( value:Align ):void
		{
			super.align = value;
			if (value == Align.LIFT)
				textFormat.align = TextFormatAlign.LEFT;
			else if (value == Align.RIGHT)
				textFormat.align = TextFormatAlign.RIGHT;
			else if (value == Align.CENTER)
				textFormat.align = TextFormatAlign.CENTER;
		}

		override public function clone():*
		{
			var data:LabelData = new LabelData();
			parse( data );
			return data;
		}
	}
}
